﻿using System;
using System.Linq;
using System.Reflection;

namespace NuSoft.ExpressionEditor.Common.Helpers
{
    /// <summary>
    /// Reflection helpers. 
    /// </summary>
    public static class ReflectionExt
    {
        /// <summary>
        /// Checks if property has at least one attribute of given type. 
        /// </summary>
        /// <typeparam name="T">Attribute type. </typeparam>
        /// <param name="prop">Property. </param>
        /// <returns>Check result. </returns>
        public static bool HasAttr<T>(this PropertyInfo prop) where T : Attribute
        {
            return prop.GetCustomAttributes(typeof(T), true).Count() > 0;
        }
    }
}